import 'dart:io';

import 'package:animal/socket/messsage_model.dart';
import 'package:animal/socket/type_model.dart';
import 'package:animal/utils/sputils/sp_config.dart';
import 'package:animal/utils/string_utils.dart';

///基础的方法
class BaseModel {
  static BaseModel inState = BaseModel();

  Future<Map> baseData(int type) async {
    Map data = {
      "ht": type,
      "pf": Platform.isAndroid ? 2 : 3,
      "t": StringUtils().generateMD5(SpConfig().getUserToken()!),
      "st": DateTime.now().millisecondsSinceEpoch.toString(),
      "s": 1,
      "snt": 0,
      "i": StringUtils().randomUuid(),
      "l": {"id": SpConfig().androidId, "av": "1.0.0", "pf": Platform.isAndroid ? 2 : 3}
    };
    return data;
  }

  Future<Map> heartData(int type) async {
    String i = StringUtils().randomUuid();
    Map data = {
      "ht": type,
      "pf": Platform.isAndroid ? 2 : 3,
      "t": StringUtils().generateMD5(SpConfig().getUserToken()!),
      "st": DateTime.now().millisecondsSinceEpoch.toString(),
      "s": 1,
      "snt": 0,
      "i": i,
      "l": {"id": SpConfig().androidId, "av": "1.0.0", "pf": Platform.isAndroid ? 2 : 3},
      "mhb":{
        "i":i,
        "s":0,
        "om":0,
      }
    };
    return data;
  }

  Future<Map> textMessageData(
      {int type = 3,
      String content = "",
      int tid = 0,
      int tt = 0,
      String? st,
      int? mt,
      String? url,
      double? width,
      double? height,
      String? op,
      GroupModel? groupModel,
      int? ut,
      UserModel? userModel}) async {
    String i = StringUtils().randomUuid();
    Map data = {
      "ht": type,
      "pf": Platform.isAndroid ? 2 : 3,
      "t": StringUtils().generateMD5(SpConfig().getUserToken()!),
      "st": DateTime.now().millisecondsSinceEpoch.toString(),
      "s": 1,
      "snt": 0,
      "i": i,
      "l": {"id": SpConfig().androidId, "av": "1.0.0", "pf": Platform.isAndroid ? 2 : 3},
      "m":{
        "i":i,
        "c": content,
        "f": userModel!.id.toString(),
        "fn": userModel.name,
        "fh": userModel.head,
        "t": tid.toString(),
        "tt": tt.toString(),
        "st": st ?? DateTime.now().millisecondsSinceEpoch.toString(),
        "mt": mt ?? 0,
        "u": url ?? "",
        "w": width ?? 0,
        "h": height ?? 0,
        "op": op ?? "",
        "gi": groupModel?.id,
        "gn": groupModel?.name,
        "gh": groupModel?.head,
        "fi": "",
        "vt": "",
        "ut": ut ?? 0,
      }
    };
    return data;
  }
}
